package expressions;

/**
 * An Expression whose value is a variable to be evaluated by asking the context
 * for its value.
 */
public abstract class Variable<T> extends Expression<T>
{
    private String varName;

    /**
     * Constructs a new Variable expression from the name of the variable.
     */
    public Variable(String varName)
    {
        this.varName = varName;
    }

    /**
     * Returns the name of the variable.
     */
    public String getVarName()
    {
        return varName;
    }

    /**
     * Evaluates the variable by asking the context what value it should
     * receive.
     */
    @Override
    public T evaluate(IContext<T> context)
    {
        return context.getValue(varName);
    }

}
